package com.branches.services;

import org.springframework.stereotype.Service;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Service
public class ScheduleTaskService {

    private final ThreadPoolExecutor taskPool = new ThreadPoolExecutor(2, 2, 0, TimeUnit.MILLISECONDS, new LinkedBlockingDeque<>());

    public void execute() {
        while (true) {
            taskPool.submit(() -> {
                System.out.println(Thread.currentThread().getName());
            });
        }

    }

    public static void main(String[] args) {
        new ScheduleTaskService().execute();
    }
}
